<?php

namespace app\home\controller;

use think\Controller;
use think\Session;

class Mulu extends Controller
{
    public function index($id)
    {
        if (Session::has('email')){
            $email = Session::get('email');
        }else{
            $email = '11';
        }

        $p = array();
        $vv = array();
        $tt = array();
        $list = array();

//        dump($id);die;
        $data = db('mulu')->field('id,name')->where('zid','eq',$id)->select();
//        dump($data);die;
        $row = db('zuopin')->field('name')->where('id','eq',$id)->find();
        foreach ($data as $v){
            $p[] = $v['id'];
        }
//        dump($p);die;
        foreach ($p as $k=>$v){
            $rev = db('mcontent')->field('detail')->where('mid','eq',$data[$k]['id'])->select();
//            $list[] = db('mcontent')->where('mid','eq',$data[$k]['id'])->paginate(2);
            $vv[$v] = $rev;
        }
//        dump($list);die;

        foreach ($vv as $key=>$val){
            foreach($val as $v){
                $tt[] = $v['detail'];
            }
        }
        $list = db('mcontent')->paginate(2,count($tt));
        $page = $list->render();
//        dump($tt);die;

        $datall = db('zuopin')->limit(8)->order('mark desc')->select();

        $comment = db('comment')->where('mid','eq',$id)->paginate(10);
        $zong = db('comment')->where('mid','eq',$id)->count('id');
        return view('/mulu/content',[
            'mhname' => $row['name'],
            'data'=>$data,
            'tt' => $tt,
            'list' => $list,
            'page' => $page,
            'datall' => $datall,
            'comment' => $comment,
            'zong'=>$zong,
            'zid'=>$id,
            'email'=>$email
        ]);
    }


    public function mulu($id)
    {
        if (Session::has('email')){
            $email = Session::get('email');
        }else{
            $email = '11';
        }

        $p = array();
        $vv = array();
        $tt = array();
        $list = array();

        //目录内容
        $data = db('mcontent')->field('mid,detail')->where('mid','eq',$id)->select();

//        作品id
        $zuopin = db('mulu')->field('zid')->where('id','eq',$data[0]['mid'])->find();

        $row = db('zuopin')->field('name')->where('id','eq',$zuopin['zid'])->find();
//        dump($row);

//        排行
        $datall = db('zuopin')->limit(8)->order('mark desc')->select();
//        dump($datall);die;

//        评论
        $comment = db('comment')->where('mid','eq',$zuopin['zid'])->paginate(10);
        $zong = db('comment')->where('mid','eq',$zuopin['zid'])->count('id');
        return view('/mulu/content',[
            'mhname' => $row['name'],
            'data'=>$data,
            'datall' => $datall,
            'comment' => $comment,
            'zong'=>$zong,
            'zid'=>$zuopin['zid'],
            'email'=>$email
        ]);
    }
}
